<template>
  <!--返款申请表单-->
  <div>
    <f-form ref="form" :action="api.payment" handlerName="refundPaymentSaveHandler"  :form-key="this.formItem.paymentId" :file-ids="fileIds">
      <f-form-item label="返款金额" type="number" name="supplierRetable" dataType="number" :value="formItem.supplierRetable" :max="formItem.supplierRetable" :precision="2" :required="true" :disabled="true"/>
      <f-form-item label="收款账户" ref="bank" type="select" name="bankId" :value="formItem.bankId" :data="api.bank.list" valueKey="bankId" label-key="bankName,bankNo" :required="true"/>
      <f-form-item label="返款日期" type="date" name="amountDate" :required="true" :value="formItem.amountDate"/>
      <f-form-item label="返款附件" type="upload" name="fkImage" :value="formItem.fkImage" value-type="json" :file-max="50" @uploadSuccess="uploadSuccess"/>
      <f-form-item label="备注" name="remark" :value="formItem.remark"/>
      <a-divider orientation="left">返款明细</a-divider>
      <f-table ref="table" rowKey="invoiceDetailsId" :columns="columns" :scroll="{x:true}" :multiple="false" handler="yesInvoiceDetailsPageListHandler" :operator="operator" :autoLoad="false" :params="queryParam" :api="api.bod">
      </f-table>
    </f-form>

  </div>
</template>
<script>
  import api from './../js/api'

  export default {
    name: 'RefundForm',
    components: {},
    data() {
      let me = this
      //操作按钮
      let operator = []
      let companyId = this.$store.getters.companyId
      let columns=[
        {
          title: '#',
          width: '60',
          align: 'center',
          customRender: (text, record, index) => index + 1
        },
        {
          title: '单号',
          align: 'center',
          dataIndex: 'orderNo'
        },
        {
          title: '发货日期',
          align: 'center',
          dataIndex: 'sendDate'
        },
        {
          title: '供货方',
          align: 'center',
          dataIndex: 'supplierName'
        },
        {
          title: '购货方',
          align: 'center',
          dataIndex: 'customName'
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: 'drugsName'
        },
        {
          title: '规格',
          align: 'center',
          dataIndex: 'drugsSpec'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'returnNum'
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'salePrice'
        },
        {
          title: '应返金额',
          align: 'center',
          needTotal: true,
          dataIndex: 'supplierRetable'
        }
      ]
      if(companyId==4){
        columns.push({
          title: '应返金额2',
          align: 'center',
          needTotal: true,
          dataIndex: 'supplierRetable2'
        })
      }
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        showForm: false,
        fileIds: [],//上传文件ID
        formItem: this.getFormItem(),
        // 表头
        columns: columns,
        operator: operator
      }
    },
    created() {
    },
    methods: {
      getFormItem() {
        return {
          paymentId: '',
          amountDate: '',
          supplierRetable: 0,
          bankId: null,
          hkImage: [],
          remark: ''
        }
      },
      //文件上传回调
      uploadSuccess(fileUrl, files, fileIds) {
        this.fileIds = fileIds
      },
      setData(data) {
        if (data && data.paymentId) {
          this.formItem.supplierRetable = data.supplierRetable
          this.queryParam.paymentId = data.paymentId
          this.$refs.table.refresh()
          this.showForm = true
          /*this.$nextTick(() => {
            this.$refs['bank'].initData({ deptId: data.deptId })
          })*/
        }
      },
      handleSubmit(callback) {
        let params = {
          invoiceId: this.queryParam.paymentId
        }
        this.$refs['form'].submit(params, this.handleSuccess)
      },
      handleSuccess() {
        this.$emit('closeDrawer', false)
      }
    }
  }
</script>
